<?php

define("MAX_VERBS", 11063);
define("URL_VERBS", "http://buscon.rae.es/draeI/SrvltGUIVerbos?IDVERBO=");

$fp = fopen("verbs/index", "r");
$nextId = fread($fp, filesize("verbs/index"));
fclose($fp);

if($nextId <= MAX_VERBS){

	$content = @file_get_contents(URL_VERBS.$nextId);
	
	if($content){
	
		$fp = fopen("verbs/".$nextId.".html", "w");
		fwrite($fp, $content);
		fclose($fp);
		$fp = fopen("verbs/index", "w");
		fwrite($fp, $nextId+1);
		fclose($fp);
			
	}else{
		$fp = fopen("verbs/errors", "a+");
		fwrite($fp, "Error in: ".URL_VERBS.$nextId."\n");
		fclose($fp);
	}
}

?>